package logic

import (
	"context"
	"edu-pro/edurpc/edurpc"
	"edu-pro/edurpc/internal/svc"
	"edu-pro/models/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type PerfectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPerfectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerfectLogic {
	return &PerfectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PerfectLogic) Perfect(in *edurpc.PerfectRequest) (*edurpc.PerfectResponse, error) {
	//个人资料修改
	var user mysql.User
	mysql.DB.Debug().Where("id = ?", in.UserId).Find(&user)
	user.AvatarUrl = in.AvatarUrl
	user.Nickname = in.Nickname
	mysql.DB.Debug().Model(&mysql.User{}).Where("id = ?", in.UserId).Updates(&user)
	return &edurpc.PerfectResponse{
		UserId:   int64(user.ID),
		Nickname: user.Nickname,
	}, nil
}
